<?php
/**
 * Created by PhpStorm.
 * User: Tioncico
 * Date: 2019/3/18 0018
 * Time: 9:40
 */

namespace App\HttpController;


use App\Utility\Mongodb\Driver;
use App\Utility\Mongodb\MongoClient;
use App\Utility\TrackerManager;
use EasySwoole\EasySwoole\Logger;
use EasySwoole\Http\AbstractInterface\Controller;
use EasySwoole\Trace\Bean\Tracker;
use EasySwoole\Utility\Random;


class Index extends Base
{
    function index()
    {
        $this->response()->write('hello world111');
//        $ret = MongoClient::getInstance()->client()->callback(function (Driver $driver){
//            $ret = $driver->getDb()->user->list->insertOne([
//                'name' =>Random::character(8),
//                'sex'=>'man',
//            ]);
//            if(!$ret){
//                return false;
//            }
//            return $ret->getInsertedId();
//        });


//        $data = [
//            'action' => 'call1',//行为名称
//            'arg' => [
//                'args1' => 'args1',
//                'args2' => 'args2'
//            ]
//        ];
//
//        $raw = serialize($data);//注意序列化类型,需要和RPC服务端约定好协议 $serializeType
//
//        $fp = stream_socket_client('tcp://127.0.0.1:9527');
//        fwrite($fp, pack('N', strlen($raw)) . $raw);
//
//        $data = fread($fp, 65533);
////做长度头部校验
//        $len = unpack('N', $data);
//        $data = substr($data, '4');
//        if (strlen($data) != $len[1]) {
//            echo 'data error';
//        } else {
//            $data = unserialize($data);
//            echo   $data->getMessage();
////    //这就是服务端返回的结果，
//            //print_r($data);//默认将返回一个response对象 通过$serializeType修改
//        }
//        fclose($fp);
////        throw new \Exception('测试',1022);
//       //$this->response()->write('888');
//       // return 'index';
//        return $this->writeJson(200, [], 'success');
    }
}